package com.lujianfei.tiananyungu.utils

import android.util.Log

object StringUtils {
    /**
     * 1期3栋 =》1.3
     */
    fun getNumberFromString(input: String): String {
        val regex = Regex("\\d+")
        val result = regex.findAll(input)
        val retFloat = StringBuilder()
        result.iterator().forEach {
            retFloat.append(it.value).append(".")
        }
        return retFloat.removeSuffix(".").toString()
    }

    fun compareVersion(version1: String, version2: String): Int {
        val v1 = version1.split('.')
        val v2 = version2.split('.')

        val minLength = minOf(v1.size, v2.size)

        for (i in 0 until minLength) {
            val num1 = v1[i].toInt()
            val num2 = v2[i].toInt()

            if (num1 < num2) {
                return -1
            } else if (num1 > num2) {
                return 1
            }
        }

        if (v1.size < v2.size) {
            return -1
        } else if (v1.size > v2.size) {
            return 1
        }

        return 0
    }
}


